<%@ page import="org.languageguide.server.*" %><jsp:useBean id="userManager" scope="application" class="org.languageguide.user.UserManager" /><html>
<head>
</head>
<body>
<%
	String name = request.getParameter("name");
	String username = request.getParameter("username");
	
	
	String email = request.getParameter("email");
	String password = request.getParameter("password");
	String lang = request.getParameter("lang");	
	if (password == null || password.isEmpty()){
		session.setAttribute("message", "Please enter a password.");
		response.sendRedirect("/user/invite.jsp?lang=" + lang);
		return;
	}

	String passwordConfirm = request.getParameter("password_confirm");
	boolean has = userManager.hasUserName(username);
	if (!has){
		org.languageguide.user.User user =  userManager.registerUser(name, username,email, password, lang);
		session.setAttribute(user.sessionId, user);
		Object redirect = session.getAttribute("redirect_url");
		if (redirect != null){
			response.sendRedirect((String)redirect);
		}
		else{
			response.sendRedirect("/user/translate_list.jsp?language=en");
		}
	}
	else{
		session.setAttribute("message", "I'm sorry. A user with this User Name already exists.");


		response.sendRedirect("/user/login.jsp?lang=" + lang);

	}
%>
</body>
</html>